home *** CD-ROM | disk | FTP | other *** search
- Path: qualcomm.com!not-for-mail
- From: drew@qualcomm.com (Drew Eckhardt)
- Newsgroups: comp.lang.c++
- Subject: Re: sprintf() in C++
- Date: 10 Apr 1996 14:18:19 -0600
- Organization: QUALCOMM, Incorporated; Boulder, CO, USA
- Message-ID: <4kh52b$34t@qualcomm.com>
- References: <4kene4$nkb@post.gsfc.nasa.gov> <4kf5bg$u8a@mule2.mindspring.com>
- NNTP-Posting-Host: littlebear.qualcomm.com
-
- In article <4kf5bg$u8a@mule2.mindspring.com>,
- Justin Rudd <rudd@mindspring.com> wrote:
- >tycho <vonrosen@nssdca.gsfc.nasa.gov> wrote:
-
- I use dynamically allocated strstream buffers where practical, since
- space isn't wasted, there's no limit on the output size, and no "magic"
- size number which some one may have to increase when more output is added
- in the future.
-
- Instead of this,
-
- >char msg[500];
- >ostrstream stream(msg,500);
-
- I'd say
-
- ostrstream stream;
-
- >stream << "An Int Value" << 10 << endl;
- >stream << "A Float Value" << 10.0f << endl;
- >stream << "Really Simple stuff" << ends << endl;
-
- And this
-
- >cout << msg;
-
- would become
-
- cout << stream.str();
-
- followed by
-
- stream.rdbuf()->freeze(0);
-
- to deallocate the buffer after use. Alternatively, you can delete the
- buffer when you're done using it, doing something like this:
-
- char *
- foo () {
- ostrstream bar;
- bar << "Replace with arbitrary meaningful stuff." << ends;
- return (bar.str());
- }
-
- ...
-
- char *tmp = foo();
- // operate on tmp here.
- delete tmp;
-
- --
- <a href="http://www.poohsticks.org/drew/">Home Page</a>
- Four boxes : soap, ballot, jury, ammo. | Work: drew@Qualcomm.COM
- Use in that order. | Play: drew@PoohSticks.ORG
-